<?php
class DBClass{

	var $dbuser = "root";
	var $dbpassword = "";
	var $dbname = "cakmafoni";
	var $dbhost = "localhost";

	function __construct($dbuser='', $dbpassword='', $dbname='', $dbhost='')
	{
		 
	}
	function  Query($query){
                $returnVal = '';
                $connect =      mysql_connect($this->dbhost,$this->dbuser,$this->dbpassword);
                
                if (!$connect) {
                        die('Could not connect: ' . mysql_error());
                }
                $db_selected = mysql_select_db($this->dbname, $connect);
                if (!$db_selected) {
                        die ('Can\'t use db : ' . mysql_error());
                }
                $query = trim($query);
                $result = mysql_query($query);

                if ( preg_match("/^(insert|INSERT|delete|DELETE|update|UPDATE|replace|REPLACE)\s+/i",$query)){
                        //insert,delete,update
                }else{
                        //select
                        $dt = array();
                        $i=0;
                        while($row = mysql_fetch_array($result))
                        {
                                        $dt[$i] = $row;
                                $i++;
                        }
                        mysql_free_result($result);
                        $returnVal = $dt;
                }
                mysql_close($connect);
                return $returnVal;
        }
	

}
?>
